package com.rytong.tools.utils;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
/**
 * InputMethodListener.java
 * @author cheng.l 2013-8-14 下午01:53:55
 */
public class InputMethodUtil {
	
	private View focusView = null;
	private InputMethodManager imm = null;
	private final static Handler handler = new Handler();
	public InputMethodUtil(){
	}
	
	/**
	 * 关闭软键盘，关闭结束后并回调
	 * @param immListener
	 */
	public void setOnCloseImmListener(Activity activity,final onCloseImmListener immListener){
		focusView = activity.getCurrentFocus();
		imm = ((InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE));
		if(null != focusView){
			handler.post(new Runnable() {
				@Override
				public void run() {
					imm.hideSoftInputFromWindow(focusView.getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);					
					immListener.closeSuccess();
				}
			});
		}else{
			immListener.closeSuccess();
		}
	}
	
	public interface onCloseImmListener{
		public void closeSuccess();
	}
}
